<?php

/**
 * 注册表单模型.
 */
class RegisterForm extends CFormModel {

    public $password;
    public $nick;
    public $email;

    /**
     * Declares the validation rules.
     * The rules state that username and password are required,
     * and password needs to be authenticated.
     */
    public function rules() {
        return array(
            array('password, email, nick', 'required', 'message' => '{attribute}不能为空!'),
            array('nick, password', 'length', 'max' => 40),
            array('email', 'length', 'max' => 120),
            array('email', 'email', 'message' => '请输入正确的邮箱！'),
        );
    }

    /**
     * Declares attribute labels.
     */
    public function attributeLabels() {
        return array(
            'nick' => '用户名',
            'email' => 'Email',
            'password' => '密码',
        );
    }

    public function checkEmail() {
        if (!preg_match("/^(?:w+.?)*w+@(?:w+.?)*w+$/",$this->email)) {
            $this->addError('email', '请输入正确的邮箱！');
        }
    }

    public function register() {
        return true;
    }

}
